package com.hnxxxy.controller;

import com.hnxxxy.pojo.Activity;
import com.hnxxxy.pojo.Association;
import com.hnxxxy.pojo.User_ass;
import com.hnxxxy.service.AuditService;
import com.hnxxxy.utils.Communal;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/b/aud")
public class AuditController {
    private static final Logger log= LogManager.getLogger(AuditController.class);

    @Autowired
    AuditService auditService;

    @Autowired
    Communal communal;

    /**
     * 查询申请社团审核信息
     * @return 所有社团社长信息
     */
    @RequestMapping(value = "/s/appAssAudInfo", method = RequestMethod.POST)
    @ResponseBody
    public String queryAppAssAudInfo(int page,int limit){
        log.debug("执行/s/appAssAudInfo接口");
        return auditService.queryAppAssAudInfo(page,limit);
    }

    /**
     * 申请社团审核
     * @return
     */
    @RequestMapping(value = "/u/appAssAudInfo", method = RequestMethod.POST)
    @ResponseBody
    public String  updateAppAssAudInfo(@RequestBody Map<String, String> map){
        log.debug("执行/s/appAssAudInfo接口");
        String sjYz = communal.sjyz(map);
        if (sjYz != null) {
            return sjYz;
        }
        Association association = new Association();
        association.Association2(Integer.parseInt(map.get("a_id")),Integer.parseInt(map.get("examine")));
        return auditService.updateAppAssAudInfo(association);
    }

    /**
     * 查询活动申请审核
     * @return 所有活动申请审核
     */
    @RequestMapping(value = "/s/actAud", method = RequestMethod.POST)
    @ResponseBody
    public String queryActAud(int page,int limit){
        log.debug("执行/s/actAud接口");
        return auditService.queryActAud(page,limit);
    }

    /**
     * 活动申请审核
     * @return
     */
    @RequestMapping(value = "/u/actAud", method = RequestMethod.POST)
    @ResponseBody
    public String  updateActAud(@RequestBody Map<String, String> map){
        log.debug("执行/u/actAud接口");
        String sjYz = communal.sjyz(map);
        if (sjYz != null) {
            return sjYz;
        }
        Activity activity = new Activity();
        activity.Activity1(Integer.parseInt(map.get("ac_id")),Integer.parseInt(map.get("ac_examine")));
        return auditService.updateActAud(activity);
    }

    /**
     * 查询加入社团审核
     * @return 加入社团审核信息
     */
    @RequestMapping(value = "/s/appAssPeo", method = RequestMethod.POST)
    @ResponseBody
    public String queryAppAssPeo(int page,int limit){
        log.debug("执行/s/appAssAudInfo接口");
        return auditService.queryAppAssPeo(page,limit);
    }

    /**
     * 加入社团审核
     * @return
     */
    @RequestMapping(value = "/u/appAssPeo", method = RequestMethod.POST)
    @ResponseBody
    public String  updateAppAssPeo(@RequestBody Map<String, String> map){
        log.debug("执行/u/appAssPeo接口");
        String sjYz = communal.sjyz(map);
        if (sjYz != null) {
            return sjYz;
        }
        User_ass user_ass = new User_ass();
        user_ass.User_ass1(Integer.parseInt(map.get("id")),Integer.parseInt(map.get("examine")));
        return auditService.updateAppAssPeo(user_ass);
    }
}
